package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import si.yun.dao.SyMenuMapper;
import si.yun.service.SyNavigation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: DZQ
 * @description: TODO
 * @date: 2021/7/28 19:40
 * @return
 */
@Service
public class SyNavigationImpl implements SyNavigation {

    @Autowired
    private SyMenuMapper dao;

/**
 * @author: DZQ
 * @description:
 * @date: 2021/7/29 10:34
 * @return
 */
    @Override
    public List<Map<String, Object>> selNavigation() {
        List<Map<String, Object>> getNavigationFather=dao.selNavigationFather(null);
        for(Map<String, Object> i:getNavigationFather){
            int id = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = selNavigationSon(id);
            i.put("children",navigationSon);
        }
        System.out.println(getNavigationFather);
        return getNavigationFather;
    }

/**
 * @author: DZQ
 * @description: TODO
 * @date: 2021/7/29 14:43
 * @return
 */
    public List<Map<String, Object>> selNavigationSon(int id) {
        List<Map<String, Object>> getNavigationFather=dao.selNavigationFather(id);
        for(Map<String, Object> i:getNavigationFather){
            int idSon = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = dao.selNavigationFather(idSon);
            i.put("children",navigationSon);
        }
        System.out.println(getNavigationFather);
        return getNavigationFather;
    }


}
